package org.example.maven.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.maven.pojo.Classification;
import org.example.maven.pojo.classification.ClassificationCategory;
import org.example.maven.pojo.classification.ClassificationCategoryAdd;
import org.example.maven.pojo.classification.ClassificationSubcategoryAdd;
import org.example.maven.pojo.classification.table.ClassificationCategoryList;
import org.example.maven.pojo.classification.table.ClassificationDetail;
import org.example.maven.pojo.classification.table.EditClassification;
import org.example.maven.pojo.classification.table.SearchClassification;
import org.example.maven.pojo.eCharts.CategoryStatsDTO;

import java.util.List;
@Mapper
public interface classificationMapper {
    //获取所有分类
    @Select("select category_id,category,subcategory_id,subcategory from classification_view")
    List<Classification> getCollectionClassification();

    //获取二级分类的id
    @Select("select id from classification_subcategory where subcategory_interval=#{subId}")
    Integer getSpecificClassification(String subId);

    //根据分类名获取id
    @Select("select id from classification_subcategory where subcategory=#{subcategory}")
    String getClassificationIdBySubcategory(String subcategory);

    //获取编辑信息
    @Select("select category_id,category,category_is_deactivate,subcategory_id,subcategory,subcategory_is_deactivate from classification_view where category_id=#{id} or subcategory_id=#{id} limit 1")
    EditClassification getEditClassification(String id);


    //获取分类信息
    @Select("select *from classification_view")
    List<ClassificationDetail> getClassificationDetail();

    //获取分类的总数
    //@Select("SELECT COUNT(*) from classification_view")
    Integer getClassificationListCount(SearchClassification searchClassification);

    //获取特定的分类
    List<ClassificationDetail> getSpecieClassification(SearchClassification searchClassification);

    //获取子分类上级分类的状态
    List<Integer> getCategoryIsDeactivateBySubcategoryInterval(@Param("ids") String[] id);

    //修改分类的状态
    void updateClassificationIsDeactivate(@Param("ids") String[] id);

    //修改分类的状态为1
    void setClassificationIsDeactivate1(@Param("ids") String[] id);

    //修改子分类状态为0
    void setClassificationSubcategory0(@Param("ids") String[] id);

    //修改子分类状态为1
    void setClassificationSubcategory1(@Param("ids") String[] id);

    //获取一级分类
    @Select("select category_id as value,category as label from classification_view")
    List<ClassificationCategory> getClassificationCategory();

    //添加父分类
    void addClassificationCategory(ClassificationCategoryAdd classificationCategoryAdd);

    //添加子分类
    void addClassificationSubcategory(ClassificationSubcategoryAdd classificationSubcategoryAdd);

    //修改一级分类
    @Update("update classification_category set category=#{category},is_deactivate=#{categoryIsDeactivate} where id=#{categoryId}")
    void updateClassificationCategory(EditClassification editClassification);

    //修改二级分类
    @Update("update classification_subcategory set subcategory=#{subcategory},is_deactivate=#{subcategoryIsDeactivate} where subcategory_interval=#{subcategoryId}")
    void updateClassificationSubcategory(EditClassification editClassification);

    //获取分类藏品柱状图
    @Select("SELECT subcategory, COUNT(*) AS count FROM collection_details GROUP BY subcategory")
    List<CategoryStatsDTO> getCategoryEcharts();

}
